package com.lz.commonlibrary.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Administrator on 2017/3/10.
 * 通过所给日期判断是前天、昨天、今天、明天、后天，其他日期返回是星期几。
 */

public class TimeInterval {
    /**
     * 日期
     */
    public static final String TODAY = "今天";
    public static final String YESTERDAY = "昨天";
    public static final String TOMORROW = "明天";
    public static final String BEFORE_YESTERDAY = "前天";
    public static final String AFTER_TOMORROW = "后天";
    public static final String SUNDAY = "星期日";
    public static final String MONDAY = "星期一";
    public static final String TUESDAY = "星期二";
    public static final String WEDNESDAY = "星期三";
    public static final String THURSDAY = "星期四";
    public static final String FRIDAY = "星期五";
    public static final String SATURDAY = "星期六";
    /**
     * 将日期信息转换成今天、明天、后天、星期
     * @param date
     * @return
     */
    public static String getDateDetail(Date date){
        Calendar today = Calendar.getInstance();
        Calendar target = Calendar.getInstance();

            today.setTime(new Date());
            today.set(Calendar.HOUR, 0);
            today.set(Calendar.MINUTE, 0);
            today.set(Calendar.SECOND, 0);
            target.setTime(date);
            target.set(Calendar.HOUR, 0);
            target.set(Calendar.MINUTE, 0);
            target.set(Calendar.SECOND, 0);
//        long intervalMilli = target.getTimeInMillis() - today.getTimeInMillis();
//        int xcts = (int) (intervalMilli / (24 * 60 * 60 * 1000));
        int todayYear = today.get(Calendar.YEAR);
        int todayMonth = today.get(Calendar.MONTH);
        int todayDay = today.get(Calendar.DAY_OF_MONTH);

        int targetYear = target.get(Calendar.YEAR);
        int targetMonth = target.get(Calendar.MONTH);
        int targetDay = target.get(Calendar.DAY_OF_MONTH);


        String str = null;
        if (todayYear== targetYear && todayMonth == targetMonth ){
            if (todayDay == targetDay){
                str = TODAY;
            }else if (todayDay+1 == targetDay){
                str = TOMORROW;
            }
        }
        if (str ==null){
            str =  TimeTools.getYearMonthDay(date);
        }
        return str;

    }




}
